#lang sicp
;;2.59
(define (union-set set1 set2)
  (cond ((empty-set? set1) set2)
        ((empty-set? set2) set1)
        ((element-of-set? (car set1) set2)
         (union-set (cdr set1) set2))
        (else
         (cons (car set1) (union-set (cdr set1) set2)))))
(define (empty-set? set) (null? set))
(define the-empty-set nil)
(define (element-of-set? element set)
  (cond ((empty-set? set) #f)
        ((equal? element (car set)) #t)
        (else
         (element-of-set? element (cdr set)))))
(define (intersection-set set1 set2)
  (cond ((or (empty-set? set1) (empty-set? set2)) the-empty-set)
        ((element-of-set? (car set1) set2)
         (cons (car set1) (intersection-set (cdr set1) set2)))
        (else
         (intersection-set (cdr set1) set2))))
(define (adjoin-set element set)
  (if (element-of-set? element set)
      set
      (cons element set)))